/*
 * $Id: ManageUser.java 42 2007-05-14 10:17:19Z aaron.day $
 */
package org.crazydays.tapestry.core.page;


import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.tapestry.IComponent;
import org.apache.tapestry.event.PageBeginRenderListener;
import org.apache.tapestry.event.PageEvent;
import org.crazydays.core.IUserService;
import org.crazydays.core.data.PolisUser;
import org.crazydays.tapestry.PolisPage;

/**
 * ManageUser
 */
public abstract class ManageUser
	extends PolisPage
	implements PageBeginRenderListener
{
	/** list users */
	public final static String LIST_USERS = "listUsers";

	/** edit user */
	public final static String EDIT_USER = "editUser";

	/** state: list users */
	public final static int STATE_LIST_USERS = 0;

	/** state: edit user */
	public final static int STATE_EDIT_USER = 1;

	/** state to string */
	public final static String[] stateStrings = { LIST_USERS, EDIT_USER };

	/**
	 * Set state.
	 * 
	 * @param state State
	 */
	public abstract void setState(int state);

	/**
	 * Get state.
	 * 
	 * @return State
	 */
	public abstract int getState();

	/**
	 * Get user service.
	 * 
	 * @return User service
	 */
	public abstract IUserService getUserService();

	/**
	 * Get title.
	 * 
	 * @return Title
	 */
	public String getTitle()
	{
		int state = getState();
		if (state < 0 || state >= stateStrings.length) {
			throw new ApplicationRuntimeException("invalid state "
					+ state);
		}

		return getMessages().getMessage(stateStrings[state] + ".title");
	}

	/**
	 * Get state block.
	 * 
	 * @return State block
	 */
	public IComponent getStateBlock()
	{
		int state = getState();
		if (state < 0 || state >= stateStrings.length) {
			throw new ApplicationRuntimeException("invalid state "
					+ state);
		}

		return getComponent(stateStrings[state] + "Block");
	}

	/**
	 * Make sure there is a user setup.
	 * 
	 * @param event Page event
	 * @see PageBeginRenderListener#pageBeginRender(PageEvent)
	 */
	public void pageBeginRender(PageEvent event)
	{
	}
}
